﻿using System;
using UnityEngine;

namespace RootMotion
{
	// Token: 0x020000D8 RID: 216
	public class CameraController : MonoBehaviour
	{
		// Token: 0x17000093 RID: 147
		// (get) Token: 0x06000647 RID: 1607 RVA: 0x000060BF File Offset: 0x000042BF
		// (set) Token: 0x06000648 RID: 1608 RVA: 0x000060C7 File Offset: 0x000042C7
		public float x { get; set; }

		// Token: 0x17000094 RID: 148
		// (get) Token: 0x06000649 RID: 1609 RVA: 0x000060D0 File Offset: 0x000042D0
		// (set) Token: 0x0600064A RID: 1610 RVA: 0x000060D8 File Offset: 0x000042D8
		public float y { get; set; }

		// Token: 0x17000095 RID: 149
		// (get) Token: 0x0600064B RID: 1611 RVA: 0x000060E1 File Offset: 0x000042E1
		// (set) Token: 0x0600064C RID: 1612 RVA: 0x000060E9 File Offset: 0x000042E9
		public float distanceTarget { get; set; }

		// Token: 0x0600064D RID: 1613 RVA: 0x000396E0 File Offset: 0x000378E0
		public virtual void Awake()
		{
			Vector3 eulerAngles = base.transform.eulerAngles;
			this.x = eulerAngles.y;
			this.y = eulerAngles.x;
			this.distanceTarget = this.distance;
			this.smoothPosition = base.transform.position;
			this.cam = base.GetComponent<Camera>();
		}

		// Token: 0x0600064E RID: 1614 RVA: 0x000060F2 File Offset: 0x000042F2
		public virtual void Update()
		{
			if (this.updateMode == CameraController.UpdateMode.Update)
			{
				this.UpdateTransform();
			}
		}

		// Token: 0x0600064F RID: 1615 RVA: 0x00006105 File Offset: 0x00004305
		public virtual void FixedUpdate()
		{
			if (this.updateMode == CameraController.UpdateMode.FixedUpdate)
			{
				this.UpdateTransform();
			}
		}

		// Token: 0x06000650 RID: 1616 RVA: 0x00006119 File Offset: 0x00004319
		public virtual void LateUpdate()
		{
			this.UpdateInput();
			if (this.updateMode == CameraController.UpdateMode.LateUpdate)
			{
				this.UpdateTransform();
			}
		}

		// Token: 0x06000651 RID: 1617 RVA: 0x0003973C File Offset: 0x0003793C
		public void UpdateInput()
		{
			if (this.target == null || !this.cam.enabled)
			{
				return;
			}
			Cursor.lockState = ((!this.lockCursor) ? CursorLockMode.None : CursorLockMode.Locked);
			Cursor.visible = !this.lockCursor;
			bool flag = this.rotateAlways || (this.rotateOnLeftButton && Input.GetMouseButton(0)) || (this.rotateOnRightButton && Input.GetMouseButton(1)) || (this.rotateOnMiddleButton && Input.GetMouseButton(2));
			if (flag)
			{
				this.x += Input.GetAxis("Mouse X") * this.rotationSensitivity;
				this.y = this.ClampAngle(this.y - Input.GetAxis("Mouse Y") * this.rotationSensitivity, this.yMinLimit, this.yMaxLimit);
			}
			this.distanceTarget = Mathf.Clamp(this.distanceTarget + this.zoomAdd, this.minDistance, this.maxDistance);
		}

		// Token: 0x06000652 RID: 1618 RVA: 0x00006133 File Offset: 0x00004333
		public void UpdateTransform()
		{
			this.UpdateTransform(Time.deltaTime);
		}

		// Token: 0x06000653 RID: 1619 RVA: 0x00039860 File Offset: 0x00037A60
		public void UpdateTransform(float deltaTime)
		{
			if (this.target == null || !this.cam.enabled)
			{
				return;
			}
			this.distance += (this.distanceTarget - this.distance) * this.zoomSpeed * deltaTime;
			this.rotation = Quaternion.AngleAxis(this.x, Vector3.up) * Quaternion.AngleAxis(this.y, Vector3.right);
			if (!this.smoothFollow)
			{
				this.smoothPosition = this.target.position;
			}
			else
			{
				this.smoothPosition = Vector3.Lerp(this.smoothPosition, this.target.position, deltaTime * this.followSpeed);
			}
			this.position = this.smoothPosition + this.rotation * (this.offset - Vector3.forward * this.distance);
			base.transform.position = this.position;
			base.transform.rotation = this.rotation;
		}

		// Token: 0x17000096 RID: 150
		// (get) Token: 0x06000654 RID: 1620 RVA: 0x0003997C File Offset: 0x00037B7C
		public float zoomAdd
		{
			get
			{
				float axis = Input.GetAxis("Mouse ScrollWheel");
				if (axis > 0f)
				{
					return -this.zoomSensitivity;
				}
				if (axis < 0f)
				{
					return this.zoomSensitivity;
				}
				return 0f;
			}
		}

		// Token: 0x06000655 RID: 1621 RVA: 0x00005EC8 File Offset: 0x000040C8
		public float ClampAngle(float angle, float min, float max)
		{
			if (angle < -360f)
			{
				angle += 360f;
			}
			if (angle > 360f)
			{
				angle -= 360f;
			}
			return Mathf.Clamp(angle, min, max);
		}

		// Token: 0x0400057E RID: 1406
		public Transform target;

		// Token: 0x0400057F RID: 1407
		public CameraController.UpdateMode updateMode = CameraController.UpdateMode.LateUpdate;

		// Token: 0x04000580 RID: 1408
		public bool lockCursor = true;

		// Token: 0x04000581 RID: 1409
		public bool smoothFollow;

		// Token: 0x04000582 RID: 1410
		public float followSpeed = 10f;

		// Token: 0x04000583 RID: 1411
		public float distance = 10f;

		// Token: 0x04000584 RID: 1412
		public float minDistance = 4f;

		// Token: 0x04000585 RID: 1413
		public float maxDistance = 10f;

		// Token: 0x04000586 RID: 1414
		public float zoomSpeed = 10f;

		// Token: 0x04000587 RID: 1415
		public float zoomSensitivity = 1f;

		// Token: 0x04000588 RID: 1416
		public float rotationSensitivity = 3.5f;

		// Token: 0x04000589 RID: 1417
		public float yMinLimit = -20f;

		// Token: 0x0400058A RID: 1418
		public float yMaxLimit = 80f;

		// Token: 0x0400058B RID: 1419
		public Vector3 offset = new Vector3(0f, 1.5f, 0.5f);

		// Token: 0x0400058C RID: 1420
		public bool rotateAlways = true;

		// Token: 0x0400058D RID: 1421
		public bool rotateOnLeftButton;

		// Token: 0x0400058E RID: 1422
		public bool rotateOnRightButton;

		// Token: 0x0400058F RID: 1423
		public bool rotateOnMiddleButton;

		// Token: 0x04000590 RID: 1424
		public Vector3 targetDistance;

		// Token: 0x04000591 RID: 1425
		public Vector3 position;

		// Token: 0x04000592 RID: 1426
		public Quaternion rotation = Quaternion.identity;

		// Token: 0x04000593 RID: 1427
		public Vector3 smoothPosition;

		// Token: 0x04000594 RID: 1428
		public Camera cam;

		// Token: 0x020000D9 RID: 217
		[Serializable]
		public enum UpdateMode
		{
			// Token: 0x04000599 RID: 1433
			Update,
			// Token: 0x0400059A RID: 1434
			FixedUpdate,
			// Token: 0x0400059B RID: 1435
			LateUpdate
		}
	}
}
